package com.zhangyongyi.carhome.adapter.findcar.episode;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.zhangyongyi.carhome.R;
import com.zhangyongyi.carhome.entity.greendao.EpisodeList;

import java.util.List;

/**
 * Created by dllo on 16/1/24.
 */
public class EpisodeAdapter extends RecyclerView.Adapter<EpisodeAdapter.MyViewHolder> {

    private List<EpisodeList> episodeLists;

    public void addData(List<EpisodeList> datas) {
        episodeLists = datas;
        notifyDataSetChanged();

    }


    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
        View view = inflater.inflate(R.layout.item_episode, null);

        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        if (episodeLists != null && episodeLists.size() > 0) {
            EpisodeList list = episodeLists.get(position);
            holder.wbody.setText(list.getWbody());
            holder.comments.setText(list.getComments());
            holder.likes.setText(list.getLikes());
        }
    }

    @Override
    public int getItemCount() {
        return episodeLists != null && episodeLists.size() > 0 ? episodeLists.size() : 0;
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        private TextView wbody, comments, likes;

        public MyViewHolder(View itemView) {
            super(itemView);
            wbody = (TextView) itemView.findViewById(R.id.tv_wbody_episode_item);
            comments = (TextView) itemView.findViewById(R.id.tv_comments_episode_item);
            likes = (TextView) itemView.findViewById(R.id.tv_likes_episode_item);
        }
    }
}
